package com.szgr.baoyin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.szgr.baoyin.R;
import com.szgr.baoyin.model.ProtectGoods;
import com.szgr.baoyin.utils.MyTool;

import java.util.List;

/**
 * Created by yang on 15/11/23.
 */
public class ProtectGoodsListAdapter extends BaseAdapter {
    private Context mContext;
    private List<ProtectGoods> data;
    public ProtectGoodsListAdapter(Context context,List<ProtectGoods> data) {
        mContext = context;
        this.data = data;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_my_order_detail_list_view,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();

        ProtectGoods protectGoods = data.get(0);
        MyTool.showPicture(mContext,holder.img_head,protectGoods.getGoods_image_url());
        holder.tv_name.setText(protectGoods.getGoods_name());
        holder.tv_price.setText("¥" + protectGoods.getGoods_price() + "元");
        holder.tv_count.setText("X" + protectGoods.getGoods_num());

        return convertView;
    }

    class ViewHolder {
        ImageView img_head;
        TextView tv_name;
        TextView tv_adv;
        TextView tv_price;
        TextView tv_count;

        public ViewHolder(View view){
            img_head = (ImageView) view.findViewById(R.id.my_order_item_image);
            tv_name = (TextView) view.findViewById(R.id.my_order_detail_name);
            tv_adv = (TextView) view.findViewById(R.id.my_order_detail_adv);
            tv_price = (TextView) view.findViewById(R.id.my_order_detail_price);
            tv_count = (TextView) view.findViewById(R.id.my_order_detail_count);
        }
    }
}
